﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace TodoSuspensionWeb
{
    public partial class ImageCSharp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ImageID"] != null)
            {
                string strQuery = "select imagen from oferta where id_oferta=@id";
                String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["TODO_SUSPENSION"].ConnectionString;
                SqlCommand cmd = new SqlCommand(strQuery);
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(Request.QueryString["ImageID"]);
                SqlConnection con = new SqlConnection(strConnString);
                SqlDataAdapter sda = new SqlDataAdapter();
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                DataTable dt = new DataTable();
                con.Open();
                sda.SelectCommand = cmd;
                sda.Fill(dt);
                con.Close();
                sda.Dispose();
                con.Dispose();
                if (dt != null && dt.Rows.Count != 0)
                {
                    Byte[] bytes = (Byte[])dt.Rows[0]["imagen"];
                    Response.Buffer = true;
                    Response.Charset = "";
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    Response.End();
                }
            }
        }
    }
}